package test07;

public class Ticket implements Runnable {
    private int ticketCount = 100;
     private Object obj=new Object();
    @Override
    public void run() {
        while (true) {
            synchronized (obj){
                if (ticketCount > 0) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    ticketCount--;
                System.out.println(Thread.currentThread().getName() + "在卖票还剩" + ticketCount  + "张票");
            } else {
                break;
            }}
        }
    }
}
